package com.yanqu.road.entity.util;

import com.yanqu.road.entity.config.system.PropertyWeightItem;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PropertyWeightItemHelper {

    private static Logger logger = LogManager.getLogger(PropertyWeightItemHelper.class.getName());

    public static Map<Integer, List<PropertyWeightItem>> parseSingleRewardMap(String configStr) {
        Map<Integer, List<PropertyWeightItem>> dataMap = new HashMap<>();
        String[] configArr = configStr.split("\\|");
        for (int i = 0; i < configArr.length; i++) {
            List<PropertyWeightItem> dataList = new ArrayList<>();
            String[] paramArr = configArr[i].split(";");
            for (String paramStr : paramArr) {
                String[] weightArr = paramStr.split(",");
                PropertyWeightItem weightItem = new PropertyWeightItem();
                weightItem.setProperty(PropertyHelper.parseStringToProperty(weightArr[0]));
                weightItem.setWeight(StringUtils.string2intSafe(weightArr[1], 0));
                dataList.add(weightItem);
            }
            if (dataList.size() > 0) {
                dataMap.put(i, dataList);
            }
        }
        return dataMap;
    }


}
